<template>
    <div>
        <div class="title_box">
          <div class="iconfont icon-left" @click="$router.go(-1)"></div>
          <div class="title">地址编辑</div>
          <div></div>
        </div>
        <div class="box">
            <van-address-edit
              :area-list="areaList"
              show-delete
              show-set-default
              show-search-result
              :search-result="searchResult"
              :area-columns-placeholder="['请选择', '请选择', '请选择']"
              @save="onSave"
              @delete="onDelete"
              @change-detail="onChangeDetail"
            />
        </div>
    </div>
</template>

<script>
import { Toast } from 'vant';
import { areaList } from '@vant/area-data';
export default {
  data() {
    return {
      areaList,
      searchResult: [],
      addressInfo:{},
      showSetDefault: true
    };
  },
  methods: {
    onSave(content) {
      this.$router.push({path:"/AddressList"})
      // 获取新增地址
      let {name,tel,city,province,county,addressDetail,isDefault} = content;
      let receiving = this.$store.getters.getData.receiving;
      let data = {
        id: receiving.length,
        name,
        tel,
        address: city+province+county+addressDetail,
        // ssq:city+province+county,
        // Detailed:addressDetail,
        isDefault
      }
      this.$store.commit("addReceiving",data)
    },
    onDelete() {
      Toast('delete');
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区',
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
    // test(){
    //     let obj = this.$route.query
    //     let newArr = []
    //     let inputVal = document.querySelectorAll(".van-field__control");
    //     for(let x in obj){
    //         newArr.push(obj[x])
    //     }
    //     newArr.splice(3,1)
    //     for(let i = 0; i<inputVal.length; i++){
    //         if(newArr.length == 0){
    //             return
    //         }
    //        inputVal[i].value = newArr[i+1]
    //     }
    //     console.log(newArr)
    // }
  },
  created(){
      console.log(this.$route.query)
  },
   mounted(){
      // this.test()

   },
};
</script>


<style lang="less" scoped>
    .title_box {
      height: 47px;
      line-height: 47px;
      padding: 7px 0px;
      text-align: center;
      background: #fff;
      border-bottom: 1px solid #E8E8E8;
      display: flex;
      justify-content: space-around;
      div:nth-child(odd){
          flex: 1;
          font-size: 18px;
      }
      .title {
        flex: 6;
        font-size: 20px;
      }
    }
</style>